#include"process.h"
#include<string.h>
#include<unistd.h>


#define SIZE 101 //进度条的读数
#define STYLE '='


//v1版本
void process()
{
    int rate=0;//进度条的进度
    char buffer[SIZE];
    memset(buffer,0,sizeof(buffer));//将buffer重置为0
    const char *lable="+x";
    while(rate<=100)
    {
        printf("[%-100s][%d%%][%c] \r" ,buffer,rate,lable[rate%2]);
        fflush(stdout);
        buffer[rate]=STYLE;//设置进度条使用的符号
        rate+=1;
        usleep(10000);
    }
    printf("\n完成\n");
}

//v2版本
void FlsuhProcess(const char*tips, double total ,double current)
{
    char buffer[SIZE];
    const char *lable="+x";

    memset(buffer,0,sizeof(buffer));

    double rante=current*100.0/total;
    int num=(int)rante;
   
    int i=0;
    for(;i<num;i++)
    {
        buffer[i]=STYLE;
    }
    
    printf("%s...[%-100s[%.2f%%][%c]\r",tips,buffer,rante,lable[num%2]);
    fflush(stdout);

    if(num==100)
    {
        printf("\n执行完成~\n");
    }
}




















